home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload Trio 2 / Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO / dir44 / dungn32.zip / CONVSRC.C < prev    next >
C/C++ Source or Header  |  1994-06-22  |  2KB  |  93 lines

  1. #include <ctype.h>                     // isdigit
  2. #include <stdio.h>
  3.  
  4. FILE *old, *new;
  5. int c, n;                              // current and next character
  6. int col;                               // current column
  7. int t;                                 // next tab stop
  8. int ta;                                // tab adjustment
  9.  
  10. void main(int argc, char *argv[])
  11. {
  12.    if (argc != 3)
  13.       return;
  14.    old = fopen(argv[1], "r");
  15.    new = fopen(argv[2], "w");
  16.  
  17.    do
  18.    {
  19.       col = 1;
  20.       ta = 0;
  21.       if ((c = getc(old)) == EOF)
  22.          break;
  23.       if (c == '\f')
  24.       {
  25.          putc(c, new);
  26.          c = getc(old);
  27.       }
  28.       if (c != 'C' && c != 'c' && c != '!' && c != '\n') // genuine code line
  29.       {
  30.          for (; c != '\t'; col++)                        // label
  31.          {
  32.             putc(c, new);
  33.             c = getc(old);
  34.          }
  35.          for (; col < 6; col++)
  36.             putc(' ', new);
  37.          ta = 2;
  38.  
  39.          c = getc(old);                             // continuation indicator
  40.          if ((n = getc(old)) == '\t' || (n == ' ' && isdigit(c)))
  41.          {
  42.             putc(c, new);
  43.             c = getc(old);
  44.             if (n == '\t')
  45.                ta += 8;
  46.             else
  47.                ta += 1;
  48.          }
  49.          else if (isdigit(c))
  50.          {
  51.             putc(c, new);
  52.             c = n;
  53.          }
  54.          else
  55.          {
  56.             putc(' ', new);
  57.             ungetc(n, old);
  58.          }
  59.          col++;
  60.       }
  61.  
  62.       if (c != '\n')
  63.          do                                    // code
  64.          {
  65.             n = getc(old);
  66.             if (c == ' ' && n == '!' && col < 49)
  67.             {
  68.                c = '\t';
  69.                ta = 0;
  70.             }
  71.             if (c == '\t' && n == '!' && col > 47)
  72.                c = ' ';
  73.             ungetc(n, old);
  74.             if (c == '\t')
  75.                for (t = (col + ta + 7) / 8 * 8 + 1, ta = 0; col < t; col++)
  76.                   putc(' ', new);
  77.             else
  78.             {
  79.                putc(c, new);
  80.                col++;
  81.             }
  82.          }
  83.          while ((c = getc(old)) != '\n' && c != EOF);
  84.       if (c == '\n')
  85.          putc(c, new);
  86.    }
  87.    while (c != EOF);
  88.  
  89.    fclose(old);
  90.    fclose(new);
  91.    return;
  92. }
  93.